package com.xsd.awen.config;

import com.xsd.awen.domain.po.LoginPo;
import org.apache.shiro.SecurityUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class MyRequest extends HttpServletRequestWrapper {
	
	public MyRequest(HttpServletRequest req) {
		super(req);
	}
	
	@Override
	public String[] getParameterValues(String name) {
		if( "updateUserId".equals(name) || "createUserId".equals(name) ){
			LoginPo loginPo = (LoginPo) SecurityUtils.getSubject().getPrincipal();
			if( loginPo == null ){
				SecurityUtils.getSubject().logout();
				SecurityUtils.getSubject().getSession().setTimeout(1);
				throw new ServiceException("session invalid");
			}
			return new String[]{loginPo.getUserId()};
		}else {
			return super.getParameterValues(name);
		}
	}

}
